namespace DotNetNuke.Entities.Tabs
{
    using DotNetNuke.Common;
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Security.Permissions;
    using System;
    using System.Collections;
    using System.Xml.Serialization;

    [XmlRoot("tab", IsNullable=false)]
    public class TabInfo
    {
        private string _AdministratorRoles = Null.NullString;
        private string _AuthorizedRoles = Null.NullString;
        private ArrayList _BreadCrumbs;
        private string _ContainerPath;
        private string _ContainerSrc = Null.NullString;
        private string _Description = Null.NullString;
        private bool _DisableLink;
        private DateTime _EndDate = Null.NullDate;
        private bool _HasChildren;
        private string _IconFile = Null.NullString;
        private bool _IsDeleted;
        private bool _IsSuperTab;
        private bool _IsVisible;
        private string _KeyWords = Null.NullString;
        private int _Level;
        private ArrayList _Modules;
        private string _PageHeadText = Null.NullString;
        private ArrayList _Panes;
        private int _ParentId = Null.NullInteger;
        private int _PortalID = Null.NullInteger;
        private int _RefreshInterval = Null.NullInteger;
        private string _SkinPath;
        private string _SkinSrc = Null.NullString;
        private DateTime _StartDate = Null.NullDate;
        private int _TabID;
        private string _TabName;
        private int _TabOrder;
        private string _TabPath = Null.NullString;
        private TabPermissionCollection _TabPermissions;
        private string _Title = Null.NullString;
        private string _Url = Null.NullString;

        public TabInfo Clone()
        {
            TabInfo objTabInfo = new TabInfo();
            objTabInfo.TabID = this.TabID;
            objTabInfo.TabOrder = this.TabOrder;
            objTabInfo.PortalID = this.PortalID;
            objTabInfo.TabName = this.TabName;
            objTabInfo.AuthorizedRoles = this.AuthorizedRoles;
            objTabInfo.IsVisible = this.IsVisible;
            objTabInfo.ParentId = this.ParentId;
            objTabInfo.Level = this.Level;
            objTabInfo.IconFile = this.IconFile;
            objTabInfo.AdministratorRoles = this.AdministratorRoles;
            objTabInfo.DisableLink = this.DisableLink;
            objTabInfo.Title = this.Title;
            objTabInfo.Description = this.Description;
            objTabInfo.KeyWords = this.KeyWords;
            objTabInfo.IsDeleted = this.IsDeleted;
            objTabInfo.Url = this.Url;
            objTabInfo.SkinSrc = this.SkinSrc;
            objTabInfo.ContainerSrc = this.ContainerSrc;
            objTabInfo.TabPath = this.TabPath;
            objTabInfo.StartDate = this.StartDate;
            objTabInfo.EndDate = this.EndDate;
            objTabInfo.TabPermissions = this.TabPermissions;
            objTabInfo.HasChildren = this.HasChildren;
            objTabInfo.SkinPath = this.SkinPath;
            objTabInfo.ContainerPath = this.ContainerPath;
            objTabInfo.IsSuperTab = this.IsSuperTab;
            objTabInfo.RefreshInterval = this.RefreshInterval;
            objTabInfo.PageHeadText = this.PageHeadText;
            if (this.BreadCrumbs != null)
            {
                IEnumerator refObjectHelperL0=null;
                objTabInfo.BreadCrumbs = new ArrayList();
                try
                {
                    refObjectHelperL0 = this.BreadCrumbs.GetEnumerator();
                    while (refObjectHelperL0.MoveNext())
                    {
                        TabInfo t = (TabInfo) refObjectHelperL0.Current;
                        objTabInfo.BreadCrumbs.Add(t.Clone());
                    }
                }
                finally
                {
                    if (refObjectHelperL0 is IDisposable)
                    {
                        (refObjectHelperL0 as IDisposable).Dispose();
                    }
                }
            }
            objTabInfo.Panes = new ArrayList();
            objTabInfo.Modules = new ArrayList();
            return objTabInfo;
        }

        [XmlIgnore]
        public string AdministratorRoles
        {
            get
            {
                return this._AdministratorRoles;
            }
            set
            {
                this._AdministratorRoles = value;
            }
        }

        [XmlIgnore]
        public string AuthorizedRoles
        {
            get
            {
                return this._AuthorizedRoles;
            }
            set
            {
                this._AuthorizedRoles = value;
            }
        }

        [XmlIgnore]
        public ArrayList BreadCrumbs
        {
            get
            {
                return this._BreadCrumbs;
            }
            set
            {
                this._BreadCrumbs = value;
            }
        }

        [XmlIgnore]
        public string ContainerPath
        {
            get
            {
                return this._ContainerPath;
            }
            set
            {
                this._ContainerPath = value;
            }
        }

        [XmlElement("containersrc")]
        public string ContainerSrc
        {
            get
            {
                return this._ContainerSrc;
            }
            set
            {
                this._ContainerSrc = value;
            }
        }

        [XmlElement("description")]
        public string Description
        {
            get
            {
                return this._Description;
            }
            set
            {
                this._Description = value;
            }
        }

        [XmlElement("disabled")]
        public bool DisableLink
        {
            get
            {
                return this._DisableLink;
            }
            set
            {
                this._DisableLink = value;
            }
        }

        [XmlElement("enddate")]
        public DateTime EndDate
        {
            get
            {
                return this._EndDate;
            }
            set
            {
                this._EndDate = value;
            }
        }

        [XmlIgnore]
        public string FullUrl
        {
            get
            {
                switch (this.TabType)
                {
                    case DotNetNuke.Entities.Tabs.TabType.File:
                        return (PortalController.GetCurrentPortalSettings().HomeDirectory + this._Url);

                    case DotNetNuke.Entities.Tabs.TabType.Normal:
                        return Globals.NavigateURL(this.TabID, this.IsSuperTab);

                    case DotNetNuke.Entities.Tabs.TabType.Tab:
                        return Globals.NavigateURL(Convert.ToInt32(this._Url));

                    case DotNetNuke.Entities.Tabs.TabType.Url:
                        return this._Url;
                }
                return "";
            }
        }

        [XmlIgnore]
        public bool HasChildren
        {
            get
            {
                return this._HasChildren;
            }
            set
            {
                this._HasChildren = value;
            }
        }

        [XmlElement("iconfile")]
        public string IconFile
        {
            get
            {
                return this._IconFile;
            }
            set
            {
                this._IconFile = value;
            }
        }

        public bool IsAdminTab
        {
            get
            {
                if (this.IsSuperTab | (this.PortalID == Null.NullInteger))
                {
                    return true;
                }
                PortalSettings settings = PortalController.GetCurrentPortalSettings();
                if (settings == null)
                {
                    PortalInfo objPortal = new PortalController().GetPortal(this.PortalID);
                    return ((this.TabID == objPortal.AdminTabId) | (this.ParentId == objPortal.AdminTabId));
                }
                return ((this.TabID == settings.AdminTabId) | (this.ParentId == settings.AdminTabId));
            }
        }

        [XmlIgnore]
        public bool IsDeleted
        {
            get
            {
                return this._IsDeleted;
            }
            set
            {
                this._IsDeleted = value;
            }
        }

        [XmlIgnore]
        public bool IsSuperTab
        {
            get
            {
                return this._IsSuperTab;
            }
            set
            {
                this._IsSuperTab = value;
            }
        }

        [XmlElement("visible")]
        public bool IsVisible
        {
            get
            {
                return this._IsVisible;
            }
            set
            {
                this._IsVisible = value;
            }
        }

        [XmlElement("keywords")]
        public string KeyWords
        {
            get
            {
                return this._KeyWords;
            }
            set
            {
                this._KeyWords = value;
            }
        }

        [XmlIgnore]
        public int Level
        {
            get
            {
                return this._Level;
            }
            set
            {
                this._Level = value;
            }
        }

        [XmlIgnore]
        public ArrayList Modules
        {
            get
            {
                return this._Modules;
            }
            set
            {
                this._Modules = value;
            }
        }

        [XmlElement("pageheadtext")]
        public string PageHeadText
        {
            get
            {
                return this._PageHeadText;
            }
            set
            {
                this._PageHeadText = value;
            }
        }

        [XmlIgnore]
        public ArrayList Panes
        {
            get
            {
                return this._Panes;
            }
            set
            {
                this._Panes = value;
            }
        }

        [XmlIgnore]
        public int ParentId
        {
            get
            {
                return this._ParentId;
            }
            set
            {
                this._ParentId = value;
            }
        }

        [XmlIgnore]
        public int PortalID
        {
            get
            {
                return this._PortalID;
            }
            set
            {
                this._PortalID = value;
            }
        }

        [XmlElement("refreshinterval")]
        public int RefreshInterval
        {
            get
            {
                return this._RefreshInterval;
            }
            set
            {
                this._RefreshInterval = value;
            }
        }

        [XmlIgnore]
        public string SkinPath
        {
            get
            {
                return this._SkinPath;
            }
            set
            {
                this._SkinPath = value;
            }
        }

        [XmlElement("skinsrc")]
        public string SkinSrc
        {
            get
            {
                return this._SkinSrc;
            }
            set
            {
                this._SkinSrc = value;
            }
        }

        [XmlElement("startdate")]
        public DateTime StartDate
        {
            get
            {
                return this._StartDate;
            }
            set
            {
                this._StartDate = value;
            }
        }

        [XmlIgnore]
        public int TabID
        {
            get
            {
                return this._TabID;
            }
            set
            {
                this._TabID = value;
            }
        }

        [XmlElement("name")]
        public string TabName
        {
            get
            {
                return this._TabName;
            }
            set
            {
                this._TabName = value;
            }
        }

        [XmlIgnore]
        public int TabOrder
        {
            get
            {
                return this._TabOrder;
            }
            set
            {
                this._TabOrder = value;
            }
        }

        [XmlIgnore]
        public string TabPath
        {
            get
            {
                return this._TabPath;
            }
            set
            {
                this._TabPath = value;
            }
        }

        [XmlArrayItem("permission"), XmlArray("tabpermissions")]
        public TabPermissionCollection TabPermissions
        {
            get
            {
                return this._TabPermissions;
            }
            set
            {
                this._TabPermissions = value;
            }
        }

        [XmlIgnore]
        public DotNetNuke.Entities.Tabs.TabType TabType
        {
            get
            {
                return Globals.GetURLType(this._Url);
            }
        }

        [XmlElement("title")]
        public string Title
        {
            get
            {
                return this._Title;
            }
            set
            {
                this._Title = value;
            }
        }

        [XmlElement("url")]
        public string Url
        {
            get
            {
                return this._Url;
            }
            set
            {
                this._Url = value;
            }
        }
    }
}

